<{include file="Public/top.html" }>
</head>
<body>
<div id="warpper">
    <div class="content">
        <div class="location">商户管理</div>
        <{include file= "Business/nav.html"}>
        <div class="form-box border0">
            <form action="" class="ui-form" id="addManagerForm">
                <div class="ui-form-item">
                    <input type="text" class="ui-text" placeholder="卡券号" id="code" name="code" required/>
                    <input type="text" class="ui-text" placeholder="密码" id="password" name="password" required/>
                    <input type="button" id="search-card" value="查询" class="ui-button"/>
                </div>
                <div id="card_info">
                    <dl>第1步：输入卡券号</dl>
                    <dl>第2步：验证卡券信息</dl>
                    <dl>第3步：使用完成</dl>
                </div>
                <div class="integral_btn-group cancel-wrapper" style="display: none">
                    <input type="button" value="使用卡券" id="cancel-btn" class="ui-button"/>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
<{include file="Public/foot.html" }>
<script>

    //根据卡券号查询卡券
    $('#search-card').click(function(event) {
        var code = $('#code').val();
        var password = $('#password').val();
        if (code == '') {
            layer.msg('请输入卡券号');
        } else {
            $.ajax({
                url: "<{U('Business/searchCard')}>",
                dataType: "json",
                data: {
                    'code': code,
                    'password':password,
                },
                type: "POST",
                success: function (data) {
                    if(data.status ==0 ){
                        var html = '<ul class="business_box">';
                        html += '<li><span>商户名：</span>'+data.data['restaurantName']+'</li>';
                        html += '<li><span>卡券名：</span>'+data.data['cardType']+'</li>';
                        html += '<li><span>序列号：</span>'+data.data['code']+'</li>';
                        html += '<li><span>有效期：</span>' +data.data['beginTime'] + '至'+ data.data['endTime']+'</li>';
                        $('.cancel-wrapper').show();
                        $('#card_info').html(html);
                    }else{
                        layer.msg(data.msg);
                    }
                },
                error: function (data) {

                },
            });
        }
    });
    //核销卡券号
    $('#cancel-btn').click(function(event){
        var code = $('#code').val();
        var password = $('#password').val();
        $.ajax({
            url: "<{U('Business/ajaxConsume')}>",
            dataType: "json",
            data: {
                'code': code,
                'password': password,
            },
            type: "POST",
            success: function (data) {
                if (data.status == 1) {
                    layer.msg(data.msg);
                }
            }
        });
    });

</script>